 package handling.channel.handler;

 import client.MapleCharacter;
 import client.MapleCharacterUtil;
 import client.MapleClient;
 import handling.world.World;
 import handling.world.WorldFamilyService;
 import handling.world.WorldFindService;
 import handling.world.family.MapleFamily;
 import handling.world.family.MapleFamilyBuff;
 import handling.world.family.MapleFamilyCharacter;
 import java.util.List;
 import server.maps.FieldLimitType;
 import tools.MaplePacketCreator;
 import tools.data.input.LittleEndianAccessor;
 import tools.packet.FamilyPacket;


 public class FamilyHandler
 {
   public static void RequestFamily(LittleEndianAccessor slea, MapleClient c) {
/*  22 */     MapleCharacter chr = c.getChannelServer().getPlayerStorage().getCharacterByName(slea.readMapleAsciiString());
/*  23 */     if (chr != null) {
/*  24 */       c.announce(FamilyPacket.getFamilyPedigree(chr));
     }
   }




   public static void OpenFamily(LittleEndianAccessor slea, MapleClient c) {
/*  32 */     c.announce(FamilyPacket.getFamilyInfo(c.getPlayer()));
   }


   public static void UseFamily(LittleEndianAccessor slea, MapleClient c) {
     MapleFamily fam;
     List<MapleFamilyCharacter> chrs;
/*  39 */     int type = slea.readInt();
/*  40 */     if ((MapleFamilyBuff.values()).length <= type) {
       return;
     }
/*  43 */     MapleFamilyBuff entry = MapleFamilyBuff.values()[type];
/*  44 */     boolean success = (c.getPlayer().getFamilyId() > 0 && c.getPlayer().canUseFamilyBuff(entry) && c.getPlayer().getCurrentRep() > entry.rep);
/*  45 */     if (!success) {
       return;
     }
/*  48 */     MapleCharacter victim = null;
/*  49 */     switch (entry) {
       case 瞬移:
/*  51 */         victim = c.getChannelServer().getPlayerStorage().getCharacterByName(slea.readMapleAsciiString());
/*  52 */         if (FieldLimitType.VipRock.check(c.getPlayer().getMap().getFieldLimit()) || c.getPlayer().isInBlockedMap()) {
/*  53 */           c.getPlayer().dropMessage(5, "Summons failed. Your current location or state does not allow a summons.");
/*  54 */           success = false; break;
/*  55 */         }  if (victim == null || (victim.isGM() && !c.getPlayer().isGM())) {
/*  56 */           c.getPlayer().dropMessage(1, "Invalid name or you are not on the same channel.");
/*  57 */           success = false; break;
/*  58 */         }  if (victim.getFamilyId() == c.getPlayer().getFamilyId() && !FieldLimitType.VipRock.check(victim.getMap().getFieldLimit()) && victim.getId() != c.getPlayer().getId() && !victim.isInBlockedMap()) {
/*  59 */           c.getPlayer().changeMap(victim.getMap(), victim.getMap().getPortal(0)); break;
         }
/*  61 */         c.getPlayer().dropMessage(5, "Summons failed. Your current location or state does not allow a summons.");
/*  62 */         success = false;
         break;

       case 召唤:
/*  66 */         victim = c.getChannelServer().getPlayerStorage().getCharacterByName(slea.readMapleAsciiString());
/*  67 */         if (FieldLimitType.VipRock.check(c.getPlayer().getMap().getFieldLimit()) || c.getPlayer().isInBlockedMap()) {
/*  68 */           c.getPlayer().dropMessage(5, "Summons failed. Your current location or state does not allow a summons.");
/*  69 */         } else if (victim == null || (victim.isGM() && !c.getPlayer().isGM())) {
/*  70 */           c.getPlayer().dropMessage(1, "Invalid name or you are not on the same channel.");
/*  71 */         } else if (victim.getTeleportName().length() > 0) {
/*  72 */           c.getPlayer().dropMessage(1, "Another character has requested to summon this character. Please try again later.");
/*  73 */         } else if (victim.getFamilyId() == c.getPlayer().getFamilyId() && !FieldLimitType.VipRock.check(victim.getMap().getFieldLimit()) && victim.getId() != c.getPlayer().getId() && !victim.isInBlockedMap()) {
/*  74 */           victim.getClient().announce(FamilyPacket.familySummonRequest(c.getPlayer().getName(), c.getPlayer().getMap().getMapName()));
/*  75 */           victim.setTeleportName(c.getPlayer().getName());
         } else {
/*  77 */           c.getPlayer().dropMessage(5, "Summons failed. Your current location or state does not allow a summons.");
         }
         return;



       case 爆率15分钟:
       case 经验15分钟:
       case 爆率30分钟:
       case 经验30分钟:
/*  87 */         entry.applyTo(c.getPlayer());
         break;
       case 团结:
/*  90 */         fam = WorldFamilyService.getInstance().getFamily(c.getPlayer().getFamilyId());
/*  91 */         chrs = fam.getMFC(c.getPlayer().getId()).getOnlineJuniors(fam);
/*  92 */         if (chrs.size() < 7) {
/*  93 */           success = false; break;
         }
/*  95 */         for (MapleFamilyCharacter chrz : chrs) {
/*  96 */           int chr = WorldFindService.getInstance().findChannel(chrz.getId());
/*  97 */           if (chr == -1) {
             continue;
           }
/* 100 */           MapleCharacter chrr = World.getStorage(chr).getCharacterById(chrz.getId());
/* 101 */           entry.applyTo(chrr);
         }
         break;
     }





















/* 126 */     if (success) {
/* 127 */       c.getPlayer().setCurrentRep(c.getPlayer().getCurrentRep() - entry.rep);
/* 128 */       c.announce(FamilyPacket.changeRep(-entry.rep, c.getPlayer().getName()));
/* 129 */       c.getPlayer().useFamilyBuff(entry);
     } else {
/* 131 */       c.getPlayer().dropMessage(5, "发生未知错误。");
     }
   }




   public static void FamilyOperation(LittleEndianAccessor slea, MapleClient c) {
/* 139 */     if (c.getPlayer() == null) {
       return;
     }
/* 142 */     MapleCharacter addChr = c.getChannelServer().getPlayerStorage().getCharacterByName(slea.readMapleAsciiString());
/* 143 */     if (addChr == null) {
/* 144 */       c.announce(FamilyPacket.sendFamilyMessage(65));
/* 145 */     } else if (addChr.getFamilyId() == c.getPlayer().getFamilyId() && addChr.getFamilyId() > 0) {
/* 146 */       c.announce(FamilyPacket.sendFamilyMessage(66));
/* 147 */     } else if (addChr.getMapId() != c.getPlayer().getMapId()) {
/* 148 */       c.announce(FamilyPacket.sendFamilyMessage(69));
/* 149 */     } else if (addChr.getSeniorId() != 0) {
/* 150 */       c.announce(FamilyPacket.sendFamilyMessage(70));
/* 151 */     } else if (addChr.getLevel() >= c.getPlayer().getLevel()) {
/* 152 */       c.announce(FamilyPacket.sendFamilyMessage(71));
/* 153 */     } else if (addChr.getLevel() < c.getPlayer().getLevel() - 20) {
/* 154 */       c.announce(FamilyPacket.sendFamilyMessage(72));

     }
/* 157 */     else if (addChr.getLevel() < 10) {
/* 158 */       c.getPlayer().dropMessage(1, "被邀请的角色等级必须大于10级.");
/* 159 */     } else if (c.getPlayer().getJunior1() > 0 && c.getPlayer().getJunior2() > 0) {
/* 160 */       c.getPlayer().dropMessage(1, "你已经有2位同学，无法继续邀请.");
/* 161 */     } else if (c.getPlayer().isGM() || !addChr.isGM()) {
/* 162 */       addChr.send(FamilyPacket.sendFamilyInvite(c.getPlayer().getId(), c.getPlayer().getLevel(), c.getPlayer().getJob(), c.getPlayer().getName()));
     }
/* 164 */     c.announce(MaplePacketCreator.enableActions());
   }

   public static void FamilyPrecept(LittleEndianAccessor slea, MapleClient c) {
/* 168 */     MapleFamily fam = WorldFamilyService.getInstance().getFamily(c.getPlayer().getFamilyId());
/* 169 */     if (fam == null || fam.getLeaderId() != c.getPlayer().getId()) {
       return;
     }
/* 172 */     fam.setNotice(slea.readMapleAsciiString());
   }




   public static void FamilySummon(LittleEndianAccessor slea, MapleClient c) {
/* 179 */     MapleFamilyBuff cost = MapleFamilyBuff.召唤;
/* 180 */     MapleCharacter tt = c.getChannelServer().getPlayerStorage().getCharacterByName(slea.readMapleAsciiString());
/* 181 */     if (c.getPlayer().getFamilyId() > 0 && tt != null && tt.getFamilyId() == c.getPlayer().getFamilyId() && !FieldLimitType.VipRock.check(tt.getMap().getFieldLimit()) && 
/* 182 */       !FieldLimitType.VipRock.check(c.getPlayer().getMap().getFieldLimit()) && tt.canUseFamilyBuff(cost) && c
/* 183 */       .getPlayer().getTeleportName().equals(tt.getName()) && tt.getCurrentRep() > cost.rep && !c.getPlayer().isInBlockedMap() && !tt.isInBlockedMap()) {

/* 185 */       boolean accepted = (slea.readByte() > 0);
/* 186 */       if (accepted) {
/* 187 */         c.getPlayer().changeMap(tt.getMap(), tt.getMap().getPortal(0));
/* 188 */         tt.setCurrentRep(tt.getCurrentRep() - cost.rep);
/* 189 */         tt.getClient().announce(FamilyPacket.changeRep(-cost.rep, tt.getName()));
/* 190 */         tt.useFamilyBuff(cost);
       } else {
/* 192 */         tt.dropMessage(5, "召唤玩家失败，您当前的位置或状态不容许召唤学院同学。");
       }
     } else {
/* 195 */       c.getPlayer().dropMessage(5, "召唤玩家失败，您当前的位置或状态不容许召唤学院同学。");
     }
/* 197 */     c.getPlayer().setTeleportName("");
   }

   public static void DeleteJunior(LittleEndianAccessor slea, MapleClient c) {
/* 201 */     int juniorid = slea.readInt();
/* 202 */     if (c.getPlayer().getFamilyId() <= 0 || juniorid <= 0 || (c.getPlayer().getJunior1() != juniorid && c.getPlayer().getJunior2() != juniorid)) {
       return;
     }

/* 206 */     MapleFamily fam = WorldFamilyService.getInstance().getFamily(c.getPlayer().getFamilyId());
/* 207 */     MapleFamilyCharacter other = fam.getMFC(juniorid);
/* 208 */     if (other == null) {
       return;
     }
/* 211 */     MapleFamilyCharacter oth = c.getPlayer().getMFC();
/* 212 */     boolean junior2 = (oth.getJunior2() == juniorid);
/* 213 */     if (junior2) {
/* 214 */       oth.setJunior2(0);
     } else {
/* 216 */       oth.setJunior1(0);
     }
/* 218 */     c.getPlayer().saveFamilyStatus();
/* 219 */     other.setSeniorId(0);

/* 221 */     MapleFamily.setOfflineFamilyStatus(other.getFamilyId(), other.getSeniorId(), other.getJunior1(), other.getJunior2(), other.getCurrentRep(), other.getTotalRep(), other.getId());

/* 223 */     MapleCharacterUtil.sendNote(other.getName(), c.getPlayer().getName(), c.getPlayer().getName() + "宣布诀别，冒险学院关系已断绝。", 0);
/* 224 */     MapleCharacter receiver = c.getChannelServer().getPlayerStorage().getCharacterByName(other.getName());
/* 225 */     if (receiver != null) {
/* 226 */       receiver.showNote();
     }
/* 228 */     if (!fam.splitFamily(juniorid, other)) {
/* 229 */       if (!junior2) {
/* 230 */         fam.resetDescendants();
       }
/* 232 */       fam.resetPedigree();
     }
/* 234 */     c.announce(FamilyPacket.sendFamilyMessage(1, other.getId()));
/* 235 */     c.announce(MaplePacketCreator.enableActions());
   }

   public static void DeleteSenior(LittleEndianAccessor slea, MapleClient c) {
/* 239 */     if (c.getPlayer().getFamilyId() <= 0 || c.getPlayer().getSeniorId() <= 0) {
       return;
     }

/* 243 */     MapleFamily fam = WorldFamilyService.getInstance().getFamily(c.getPlayer().getFamilyId());
/* 244 */     MapleFamilyCharacter mgc = fam.getMFC(c.getPlayer().getSeniorId());
/* 245 */     MapleFamilyCharacter mgc_ = c.getPlayer().getMFC();
/* 246 */     mgc_.setSeniorId(0);
/* 247 */     boolean junior2 = (mgc.getJunior2() == c.getPlayer().getId());
/* 248 */     if (junior2) {
/* 249 */       mgc.setJunior2(0);
     } else {
/* 251 */       mgc.setJunior1(0);
     }

/* 254 */     MapleFamily.setOfflineFamilyStatus(mgc.getFamilyId(), mgc.getSeniorId(), mgc.getJunior1(), mgc.getJunior2(), mgc.getCurrentRep(), mgc.getTotalRep(), mgc.getId());

/* 256 */     c.getPlayer().saveFamilyStatus();
/* 257 */     MapleCharacterUtil.sendNote(mgc.getName(), c.getPlayer().getName(), c.getPlayer().getName() + "宣布诀别，冒险学院关系已断绝。", 0);
/* 258 */     MapleCharacter receiver = c.getChannelServer().getPlayerStorage().getCharacterByName(mgc.getName());
/* 259 */     if (receiver != null) {
/* 260 */       receiver.showNote();
     }
/* 262 */     if (!fam.splitFamily(c.getPlayer().getId(), mgc_)) {
/* 263 */       if (!junior2) {
/* 264 */         fam.resetDescendants();
       }
/* 266 */       fam.resetPedigree();
     }
/* 268 */     c.announce(FamilyPacket.sendFamilyMessage(1, mgc.getId()));
/* 269 */     c.announce(MaplePacketCreator.enableActions());
   }

   public static void AcceptFamily(LittleEndianAccessor slea, MapleClient c) {
/* 273 */     MapleCharacter inviter = c.getPlayer().getMap().getCharacterById(slea.readInt());
/* 274 */     if (inviter != null && c.getPlayer().getSeniorId() == 0 && (c.getPlayer().isGM() || !inviter.isHidden()) && inviter.getLevel() - 20 <= c.getPlayer().getLevel() && inviter.getLevel() >= 10 && inviter.getName().equals(slea.readMapleAsciiString()) && inviter.getNoJuniors() < 2 && c

/* 276 */       .getPlayer().getLevel() >= 10) {
/* 277 */       boolean accepted = (slea.readByte() > 0);
/* 278 */       inviter.getClient().announce(FamilyPacket.sendFamilyJoinResponse(accepted, c.getPlayer().getName()));
/* 279 */       if (accepted) {

/* 281 */         c.announce(FamilyPacket.getSeniorMessage(inviter.getName()));
/* 282 */         int old = (c.getPlayer().getMFC() == null) ? 0 : c.getPlayer().getMFC().getFamilyId();
/* 283 */         int oldj1 = (c.getPlayer().getMFC() == null) ? 0 : c.getPlayer().getMFC().getJunior1();
/* 284 */         int oldj2 = (c.getPlayer().getMFC() == null) ? 0 : c.getPlayer().getMFC().getJunior2();
/* 285 */         if (inviter.getFamilyId() > 0 && WorldFamilyService.getInstance().getFamily(inviter.getFamilyId()) != null) {
/* 286 */           MapleFamily fam = WorldFamilyService.getInstance().getFamily(inviter.getFamilyId());

/* 288 */           c.getPlayer().setFamily((old <= 0) ? inviter.getFamilyId() : old, inviter.getId(), (oldj1 <= 0) ? 0 : oldj1, (oldj2 <= 0) ? 0 : oldj2);
/* 289 */           MapleFamilyCharacter mf = inviter.getMFC();
/* 290 */           if (mf.getJunior1() > 0) {
/* 291 */             mf.setJunior2(c.getPlayer().getId());
           } else {
/* 293 */             mf.setJunior1(c.getPlayer().getId());
           }
/* 295 */           inviter.saveFamilyStatus();
/* 296 */           if (old > 0 && WorldFamilyService.getInstance().getFamily(old) != null) {
/* 297 */             MapleFamily.mergeFamily(fam, WorldFamilyService.getInstance().getFamily(old));
           } else {
/* 299 */             c.getPlayer().setFamily(inviter.getFamilyId(), inviter.getId(), (oldj1 <= 0) ? 0 : oldj1, (oldj2 <= 0) ? 0 : oldj2);
/* 300 */             fam.setOnline(c.getPlayer().getId(), true, c.getChannel());
/* 301 */             c.getPlayer().saveFamilyStatus();
           }
/* 303 */           if (fam != null) {
/* 304 */             if (inviter.getNoJuniors() == 1 || old > 0) {
/* 305 */               fam.resetDescendants();
             }
/* 307 */             fam.resetPedigree();
           }
         } else {
/* 310 */           int id = MapleFamily.createFamily(inviter.getId());
/* 311 */           if (id > 0) {

/* 313 */             MapleFamily.setOfflineFamilyStatus(id, 0, c.getPlayer().getId(), 0, inviter.getCurrentRep(), inviter.getTotalRep(), inviter.getId());
/* 314 */             MapleFamily.setOfflineFamilyStatus(id, inviter.getId(), (oldj1 <= 0) ? 0 : oldj1, (oldj2 <= 0) ? 0 : oldj2, c.getPlayer().getCurrentRep(), c.getPlayer().getTotalRep(), c.getPlayer().getId());
/* 315 */             inviter.setFamily(id, 0, c.getPlayer().getId(), 0);
/* 316 */             inviter.finishAchievement(36);
/* 317 */             c.getPlayer().setFamily(id, inviter.getId(), (oldj1 <= 0) ? 0 : oldj1, (oldj2 <= 0) ? 0 : oldj2);
/* 318 */             MapleFamily fam = WorldFamilyService.getInstance().getFamily(id);
/* 319 */             fam.setOnline(inviter.getId(), true, inviter.getClient().getChannel());
/* 320 */             if (old > 0 && WorldFamilyService.getInstance().getFamily(old) != null) {
/* 321 */               MapleFamily.mergeFamily(fam, WorldFamilyService.getInstance().getFamily(old));
             } else {
/* 323 */               fam.setOnline(c.getPlayer().getId(), true, c.getChannel());
             }
/* 325 */             fam.resetDescendants();
/* 326 */             fam.resetPedigree();
           }
         }
/* 329 */         c.announce(FamilyPacket.getFamilyInfo(c.getPlayer()));
       }
     }
   }
 }


/* Location:              C:\PGX\Server.jar!\handling\channel\handler\FamilyHandler.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */